/**
 * @param {string} text1
 * @param {string} text2
 * @return {number}
 */
 var longestCommonSubsequence = function (text1, text2) {
    let m = text1.length
    let n = text2.length
    const arr = new Array(m + 1).fill(0).map(() => new Array(n + 1).fill(0))
    for (let i = 1; i <= m; ++i) {
      const c1 = text1[i - 1]
      for (let j = 1; j <= n; ++j) {
        const c2 = text2[j - 1]
        if (c1 === c2) {
          arr[i][j] = arr[i - 1][j - 1] + 1
        } else {
          arr[i][j] = Math.max(arr[i][j - 1], arr[i - 1][j])
        }
  
      }
    }
    return arr[m][n]
  };